// pages/admin/department/departAddStepOne/departAddStepOne.js
const app = getApp();
import Api from '../../../../utils/http'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    departmentName: '', //部门名称
  },
  //跳转 添加部门负责人
  addDepartmentAdmin: function () {
    console.log(this.data)
    var departmentName = this.data.departmentName;
    if (departmentName == '') {
      wx.showToast({
        title: '请输入部门名称',
        icon: 'none'
      })
      return;
    } else {
      this.department();
    }
  },

  //获取部门名称
  departNameInput: function (e) {
    var departmentName = e.detail.value;
    this.setData({
      departmentName: departmentName
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },
  //添加部门
  department: function () {
    var that = this;
    let uid = wx.getStorageSync('userid')
    var param = {
      uid: uid.id,
      title: that.data.departmentName
    }
    console.log(param)
    Api.ajax('/app/Zmanage/addDepartment', param).then(res => {
      console.log(res)
      if (res.code == 200) {
        // that.setData({
        //   departmentName: ''
        // });
        wx.showToast({
          title: '添加成功',
          icon: 'success',
          duration: 2000,
        });
        let time=res.data.create_time;
        let did=res.data.id;
        let name=that.data.departmentName
        wx.navigateTo({
          url: `/pages/admin/department/departAddStepTwo/departAddStepTwo?time=${time}&did=${did}&name=${name}`,
        })
      } else if (res.code == 202){
        wx.showToast({
          title: '该部门已存在',
          icon: 'none',
          duration: 2000,
        })
      }else{
        wx.showToast({
          title: '添加失败',
          icon: 'none',
          duration: 2000,
        })
      }
    })
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})